#include <iostream>

using namespace std;

typedef long long LL;
const int N = 1e6 + 10;

int m, n;
string t, s;
int d[N]; 

bool check(int i, int j)
{
	if(s[i] == '0' && s[j] == '1') return true;
	else if(s[i] == '1' && s[j] == '0') return true;
	else if(s[i] == '#' && s[j] == '#') return true;
	return false;
}

int main()
{
	cin >> m >> t;
	s += ' ';
	for(auto ch : t)
	{
		s += '#';
		s += ch;
	}
	s += "##";
	n = s.size() - 2;
	
	d[1] = 1;
	LL ret = 0;
	
	for(int i = 3, l = 1, r = 1; i <= n; i += 2)
	{
		int len = r >= i ? min(d[r - i + l], r - i + 1) : 1;
		while(check(i + len, i - len)) len++;
		if(i + len - 1 > r) r = i + len - 1, l = i - len + 1;
		d[i] = len;
		
		ret = ret + d[i] / 2;
	} 
	
	cout << ret << endl;
	
	return 0;
}













